package org.thinker.common;

import javax.annotation.Resource;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapClient;

public abstract class AbstractDAO<E,K> implements GenericDAO<E, K>{
	
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMap;
	
	protected String namespace;
	
	public SqlMapClient getSqlMap() {
		return sqlMap;
	}

	public void setNamespace(String namespace){
		this.namespace = namespace;
	}

	@Override
	public void create(E vo) throws Exception {
		sqlMap.insert(namespace + ".create", vo);
	}

	@Override
	public E read(K key) throws Exception {
		return (E)sqlMap.queryForList(namespace + ".read", key);
	}

	@Override
	public void update(E vo) throws Exception {
		sqlMap.update(namespace + ".update", vo);
	}

	@Override
	public void delete(K key) throws Exception {
		sqlMap.delete(namespace + ".delete", key);
	}
	
}
